package net.aetherial.context.grounding.estimators;

import java.util.*;

/**
 * Generates estimates based upon the pronoun use frequency. Unused in the current version of the system.
 */

public class PronounEstimator extends Estimator
{
	private static Set<String> pronouns;
	
	static 
	{
		String[] list = { "all", "another", "any", "anybody", "anyone", "anything", "both", 
			"each", "each other", "either", "everybody", "everyone", "everything", "few", "he", "her", "hers", 
			"herself", "him", "himself", "his", "i", "it", "its", "itself", "little", "many", "me", "mine", 
			"more", "most", "much", "myself", "neither", "no one", "nobody", "none", "nothing", "one", 
			"one another", "other", "others", "ours", "ourselves", "several", "she", "some", "somebody", 
			"someone", "something", "that", "theirs", "them", "themselves", "these", "they", "this", "those", 
			"us", "we", "what", "whatever", "which", "whichever", "who", "whoever", "whom", "whomever", 
			"whose", "you", "yours", "yourself", "yourselves" };

		pronouns = new HashSet<String> ();
		
		for (String word: list)
			pronouns.add (word);
	}
	
	/**
	 * Generates an estimate based on the proportion of pronouns to regular nouns.
	 * 
	 * @see net.aetherial.context.grounding.estimators.Estimator#estimate(java.lang.String, java.lang.String, double)
	 */
	
	public double estimate (String sender, String contribution, double score) 
	{
		String lower = contribution.toLowerCase ();

		String[] words = lower.split (" ");
		
		double total = 0.0;
		double count = 0.0;
		
		for (String word: words)
		{
			if (pronouns.contains (word))
				count++;
			total++;
		}
		
		return count / total;
	}

	/**
	 * Returns "PronounEstimator".
	 * 
	 * @see net.aetherial.context.grounding.estimators.Estimator#getName()
	 */
	
	public String getName() 
	{
		return "PronounEstimator";
	}

}
